package mylab.io.base.fsm;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.function.Consumer;

import mylab.base.foundation.lang.Callback;

public class DasRunningState extends AbstractState {

    @Override
    public DasStatus getStatus() {
        return DasStatus.Running;
    }

    @Override
    public List<DasAction> getSupportedActions() {
        return Lists.newArrayList(DasAction.Stop, DasAction.Dispose);
    }

    @Override
    public void execute(FsmContext context, DasAction action, Callback<Void> callback) {
        super.execute(context, action, callback);

        switch (action) {
            case Stop ->
                    context.stopFunc(Callback.simple(callback, (Consumer<Void>) unused -> context.setDasState(new DasStoppedState())));
            case Dispose ->
                    context.disposeFunc(Callback.simple(callback, (Consumer<Void>) unused -> context.setDasState(new DasShutdownState())));
        }
    }
}
